Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 11, 2025

This PR addresses Issue #7907 by adding a keyboard shortcut to quickly add selected code to context.

Changes

  • Added keyboard shortcut configuration in package.json:
    • macOS: Cmd+'
    • Windows/Linux: Ctrl+'
  • Enhanced the addToContext command to also focus the input field after adding content
  • Shortcut is only active when editor has text selection (editorTextFocus && editorHasSelection)

Benefits

  • Provides a faster, keyboard-driven workflow for adding code context
  • Automatically focuses the input field so users can immediately start typing
  • Maintains consistency with existing "Add to Context" behavior from the context menu

Testing

  • All existing tests pass (3778 tests)
  • Linting and type checking pass
  • Manual testing confirms the shortcut works as expected

Closes #7907


Important

Adds a keyboard shortcut for the 'Add to Context' action, enhancing workflow by focusing the input field post-action and ensuring shortcut activation only when text is selected.

  • Behavior:
    • Adds keyboard shortcut for addToContext command in package.json.
    • Shortcut: Cmd+' for macOS, Ctrl+' for Windows/Linux.
    • Shortcut active when editorTextFocus && editorHasSelection.
    • Enhances addToContext to focus input field after action.
  • Benefits:
    • Faster workflow for adding code to context.
    • Consistent with context menu behavior.
  • Testing:
    • All tests pass (3778 tests).
    • Linting and type checking pass.
    • Manual testing confirms shortcut functionality.

This description was created by Ellipsis for be146d8. You can customize this summary. It will automatically update as commits are pushed.

@roomote roomote bot requested review from cte, jr and mrubens as code owners September 11, 2025 18:16
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Sep 11, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 11, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code because apparently I trust no one, not even myself.

await provider.postMessageToWebview({ type: "action", action: "focusInput" })
}
}, 100)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new focus input functionality lacks test coverage. Since I'm the one who wrote this, I should probably add tests to verify the focus behavior works correctly - but here we are.

await vscode.commands.executeCommand("roo-cline.SidebarProvider.focus")
}
// Send focus input message after a short delay to ensure the view is ready
setTimeout(async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using setTimeout with a fixed 100ms delay intentional? This could be unreliable on slower systems or when the webview takes longer to initialize. Consider using a more robust approach like waiting for a confirmation message from the webview or implementing a promise-based mechanism.

setTimeout(async () => {
const provider = ClineProvider.getVisibleInstance()
if (provider) {
await provider.postMessageToWebview({ type: "action", action: "focusInput" })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postMessageToWebview call here could throw if something goes wrong. Consider wrapping this in a try-catch to handle potential promise rejections gracefully:

Suggested change
await provider.postMessageToWebview({ type: "action", action: "focusInput" })
try {
await provider.postMessageToWebview({ type: "action", action: "focusInput" })
} catch (error) {
// Log error but don't break the flow
console.error("Failed to focus input:", error)
}

src/package.json Outdated
"keybindings": [
{
"command": "roo-cline.addToContext",
"key": "cmd+'",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment explaining why Cmd/Ctrl+' was chosen as the keyboard shortcut. This helps future maintainers understand the decision and ensures consistency with common IDE patterns.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 12, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 12, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Sep 12, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Sep 12, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 12, 2025
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things on this:

  1. There's a lot of logic around waiting - could use something like pWaitFor instead of rolling our own?
  2. Cline uses the same keyboard shortcut. How much does this conflict?
  3. Can we add some indication in the UI that this exists? Probably showing the keyboard shortcut in the context menu.

@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Changes Requested] in Roo Code Roadmap Sep 15, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 15, 2025
… only)

- Added keyboard shortcut configuration in package.json:
  - macOS: Cmd+'
  - Windows/Linux: Ctrl+'
- Shortcut is only active when editor has text selection
- Removed all code implementation per review feedback
@daniel-lxs daniel-lxs force-pushed the feat/add-to-context-keyboard-shortcut branch from 4dce67a to 395e42e Compare September 15, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Keyboard shortcut to Add to Context from editor selection

4 participants